﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ECCSystem.DataAccess
{ 
    class ClsEntry:DBObject 
    {
        public ClsEntry()
        { }

        public DataSet GetList(int intOperatorID,string strECCDate)
        {
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@OperatorID", SqlDbType.Int),
                new SqlParameter("@ECCDate",SqlDbType.VarChar,30)
            };
            parameters[0].Value = intOperatorID;
            parameters[1].Value = strECCDate;
            return this.RunProcedure("sp_BusinessInfo_List", parameters, "BusinessInfo");
        }

        public int AddEntry(int intMailCategoryID,string strMailSubject,string strSaleCommodityID,
            float fltOperationTime,float fltPauseTime,int intHoldCount,string strBizStatus,
            int intOperatorID,string strECCDate)
        {
            int intRowsAffected = 0;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@MailCategoryID",SqlDbType.Int),
                new SqlParameter("@MailSubject",SqlDbType.NVarChar,50),new SqlParameter("@SaleCommodityID",SqlDbType.VarChar,100),
                new SqlParameter("@OperationTime",SqlDbType.Float),new SqlParameter("@PauseTime",SqlDbType.Float),
                new SqlParameter("@HoldCount",SqlDbType.Int),new SqlParameter("@BizStatus",SqlDbType.NVarChar,20),
                new SqlParameter("@OperatorID",SqlDbType.Int),new SqlParameter("@ECCDate",SqlDbType.VarChar,30)
            };
            parameters[0].Value = intMailCategoryID;
            parameters[1].Value = strMailSubject;
            parameters[2].Value = strSaleCommodityID;
            parameters[3].Value = fltOperationTime;
            parameters[4].Value = fltPauseTime;
            parameters[5].Value = intHoldCount;
            parameters[6].Value = strBizStatus;
            parameters[7].Value = intOperatorID;
            parameters[8].Value = strECCDate;
            return this.RunProcedure("sp_BusinessInfo_Add", parameters, ref intRowsAffected);
        }

        public DataSet GetEntry(int intBusinessID)
        {
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int) };
            parameters[0].Value = intBusinessID;
            return this.RunProcedure("sp_BusinessInfo_GetEntry", parameters, "BusinessInfo");
        }

        public int EditHoldEntry(int intMailCategoryID, string strMailSubject, string strSaleCommodityID,
            float fltOperationTime, float fltPauseTime, int intHoldCount, string strBizStatus,
            int intOperatorID, string strECCDate,int intBusinessID)
        {
            int intRowsAffected = 0;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@MailCategoryID",SqlDbType.Int),
                new SqlParameter("@MailSubject",SqlDbType.NVarChar,50),new SqlParameter("@SaleCommodityID",SqlDbType.VarChar,100),
                new SqlParameter("@OperationTime",SqlDbType.Float),new SqlParameter("@PauseTime",SqlDbType.Float),
                new SqlParameter("@HoldCount",SqlDbType.Int),new SqlParameter("@BizStatus",SqlDbType.NVarChar,20),
                new SqlParameter("@OperatorID",SqlDbType.Int),new SqlParameter("@ECCDate",SqlDbType.VarChar,30),
                new SqlParameter("@ID",SqlDbType.Int)
            };
            parameters[0].Value = intMailCategoryID;
            parameters[1].Value = strMailSubject;
            parameters[2].Value = strSaleCommodityID;
            parameters[3].Value = fltOperationTime;
            parameters[4].Value = fltPauseTime;
            parameters[5].Value = intHoldCount;
            parameters[6].Value = strBizStatus;
            parameters[7].Value = intOperatorID;
            parameters[8].Value = strECCDate;
            parameters[9].Value = intBusinessID;
            return this.RunProcedure("sp_BusinessInfo_EditHold", parameters, ref intRowsAffected);
        }
        public int EditEntry(int intMailCategoryID, string strMailSubject, string strSaleCommodityID,int intID)
        {
            int intRowsAffected = 0;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@MailCategoryID",SqlDbType.Int),
                new SqlParameter("@MailSubject",SqlDbType.NVarChar,50),new SqlParameter("@SaleCommodityID",SqlDbType.VarChar,100),
                new SqlParameter("@ID",SqlDbType.Int)
            };
            parameters[0].Value = intMailCategoryID;
            parameters[1].Value = strMailSubject;
            parameters[2].Value = strSaleCommodityID;
            parameters[3].Value = intID;
            return this.RunProcedure("sp_BusinessInfo_Edit", parameters, ref intRowsAffected);

        }

        public int DeleteEntry(int intBusinessID)
        {
            int intRowsAffected = 0;
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int) };
            parameters[0].Value = intBusinessID;
            return this.RunProcedure("sp_BusinessInfo_Delete", parameters, ref intRowsAffected); 
        }
    }
}
